home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 3 / CD ACTUAL 3.iso / linux / system / bsvc-1.000 / bsvc-1 / bsvc-1.0.4 / src / Framework / StatInfo.cxx < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-26  |  3.6 KB  |  132 lines

  1. /////////////////////////////////////////////////////////////////////////////// //
  2. // $Id: StatInfo.cxx,v 1.1 1994/02/18 19:53:40 bmott Exp $
  3. /////////////////////////////////////////////////////////////////////////////// //
  4. // StatInfo.cxx
  5. //
  6. //   This class is used by BasicCPU (and derived classes) to manage a list of
  7. // of statistics objects.
  8. //
  9. //
  10. // BSVC "A Microprocessor Simulation Framework"
  11. // Copyright (c) 1993
  12. // By: Bradford W. Mott
  13. // December 5,1993
  14. //
  15. ///////////////////////////////////////////////////////////////////////////////
  16. // $Log: StatInfo.cxx,v $
  17. // Revision 1.1  1994/02/18  19:53:40  bmott
  18. // Initial revision
  19. //
  20. ///////////////////////////////////////////////////////////////////////////////
  21.  
  22. #include <string.h>
  23. #include "StatInfo.hxx"
  24.  
  25. ///////////////////////////////////////////////////////////////////////////////
  26. // One of the StatisticInformation constructor
  27. ///////////////////////////////////////////////////////////////////////////////
  28. StatisticInformation::StatisticInformation(const char* s)
  29. {
  30.   statistic=new char[strlen(s)+1];
  31.   strcpy(statistic,s);
  32. }
  33.  
  34. ///////////////////////////////////////////////////////////////////////////////
  35. //  The other StatisticInformation constructor
  36. ///////////////////////////////////////////////////////////////////////////////
  37. StatisticInformation::StatisticInformation()
  38. {
  39.   statistic=(void*)0;
  40. }
  41.  
  42. ///////////////////////////////////////////////////////////////////////////////
  43. // The StatisticInformation destructor
  44. ///////////////////////////////////////////////////////////////////////////////
  45. StatisticInformation::~StatisticInformation()
  46. {
  47.   delete[] statistic;
  48. }
  49.  
  50. ///////////////////////////////////////////////////////////////////////////////
  51. // Set the statistic, and description
  52. ///////////////////////////////////////////////////////////////////////////////
  53. void StatisticInformation::Set(const char* s)
  54. {
  55.   delete[] statistic;
  56.  
  57.   statistic=new char[strlen(s)+1];
  58.   strcpy(statistic,s);
  59. }
  60.  
  61.  
  62. ///////////////////////////////////////////////////////////////////////////////
  63. // The StatisticalInformationList constructor
  64. ///////////////////////////////////////////////////////////////////////////////
  65. StatisticalInformationList::StatisticalInformationList(BasicCPU* cpu)
  66. {
  67.   head=tail=(void*)0;
  68.   number_of_elements=0;
  69.   cpu->BuildStatisticalInformationList(this);
  70. }
  71.  
  72. ///////////////////////////////////////////////////////////////////////////////
  73. // The class destructor
  74. ///////////////////////////////////////////////////////////////////////////////
  75. StatisticalInformationList::~StatisticalInformationList()
  76. {
  77.   StatisticInformationNode* p;
  78.   StatisticInformationNode* q;
  79.  
  80.   // Delete the list of nodes
  81.   p=head;
  82.   while (p!=(void*)0)
  83.   {
  84.     q=p->next;
  85.     delete p;
  86.     p=q;
  87.   }
  88. }
  89.  
  90. ///////////////////////////////////////////////////////////////////////////////
  91. // Append a new node to the list
  92. ///////////////////////////////////////////////////////////////////////////////
  93. void StatisticalInformationList::Append(const char* statistic)
  94. {
  95.   StatisticInformationNode* n;
  96.   n = new StatisticInformationNode(statistic);
  97.  
  98.   if(tail==(void*)0)
  99.   {
  100.     head = tail = n;
  101.   }
  102.   else
  103.   {
  104.     tail->next = n;
  105.     tail = n;
  106.   } 
  107.  
  108.   ++number_of_elements;
  109. }
  110.  
  111. ///////////////////////////////////////////////////////////////////////////////
  112. // Return a specific element from the list
  113. ///////////////////////////////////////////////////////////////////////////////
  114. int StatisticalInformationList::Element(int index,StatisticInformation& info)
  115. {
  116.   StatisticInformationNode* p;
  117.   int t;
  118.  
  119.   for(t=0,p=head;(t<index) && (p!=(void*)0);++t,p=p->next);
  120.  
  121.   if(t==index) 
  122.   {
  123.     info.Set(p->Statistic());
  124.     return(1);
  125.   }
  126.   else
  127.   {
  128.     return(0);
  129.   }
  130. }
  131.  
  132.